// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
// 引入reset.css样式
import '@/assets/css/reset.css'

import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

Vue.config.lang = 'zh-cn'
const i18n_zh = new VueI18n({
  locale: 'zh-cn',
  zhLocale
})
const i18n_en = new VueI18n({
  locale: 'en',
  enLocale
})
import ElementUI from 'element-ui'
import '@/assets/css/element-#14D288/index.css'

import '@/assets/iconfonts/iconfont/iconfont.css'

import echarts from 'echarts';
import 'echarts/dist/extension/dataTool.js';

import { store } from '@/store/store'

require('./mock/mock.js')

Vue.use(ElementUI)
Vue.use(VueAxios, axios)
Vue.config.productionTip = false

Vue.use(echarts)
Vue.prototype.$echarts = echarts

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  i18n_en,
  // components: { App },
  // template: '<App/>'
  render: h => h(App)
})

/*设置路由拦截器 */
router.beforeEach((to, from, next) => {
  if (store.state.mode == 'dev') {
    //开发模式，不拦截
    if (to.path == '/') {
      next({
        path: '/main'
      })
    } else {
      next()
    }
  } else {
    if (to.path === '/login') {
      next()
    } else if (!localStorage.getItem('access_token')) {
      if (to.path == '/') {
        next({
          path: '/main'
        })
      } else {
        next()
      }
    } else {
      next({
        path: '/login'
      })
    }
  }
})
